package com.schematic.flixel.spaceinvaders
{
import org.flixel.FlxSprite;
import org.flixel.FlxG;

public class Bullet extends FlxSprite
{
    //--------------------------------------------------------------------------
    //
    //  Constants
    //
    //--------------------------------------------------------------------------
    //----------------------------------
    //  CANNON
    //----------------------------------
    /**
     * cannon bullet
     */
    public static const CANNON:String = "cannon";

    //----------------------------------
    //  INVADER
    //----------------------------------
    /**
     * alien bullet
     */
    public static const INVADER:String = "invader";

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new instance of this class.
     */
    public function Bullet(x:Number, y:Number, kind:String = CANNON)
    {
        super(x, y);
        createGraphic(2, 15, 0xFFFFFFFF);
        this.kind = kind;
        velocity.y = kind == CANNON ? -500 : 300;
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------
    
    //----------------------------------
    //  kind
    //----------------------------------
    /**
     *  @private
     */
    private var kind:String;
    
    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - FlxObject
    //
    //--------------------------------------------------------------------------
    
    override public function update():void
    {
        super.update();
        
        if (kind == CANNON)
        {
            if (y < -height)
                kill();
        }
        else
        {
            if (y > FlxG.height + height)
                kill();
        }
    }
}
}